#include "widget.h"
#include "ui_widget.h"
#include<QListWidget>
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
//    ui->listWidget->addItem("C++");
//    ui->listWidget->addItem("java");
//    ui->listWidget->addItem("go");

}

Widget::~Widget()
{
    delete ui;
}



void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current!=NULL&&previous!=NULL)
    {
        qDebug()<<"当前选中的是"<<current->text()
               <<"之前选中的是"<<previous->text();
    }
}

void Widget::on_pushButton_clicked()
{
    if(!ui->lineEdit->text().isEmpty()){
        ui->listWidget->addItem(ui->lineEdit->text());
    }
}

void Widget::on_pushButton_2_clicked()
{
    int row=ui->listWidget->currentRow();
    ui->listWidget->takeItem(row);
}

